package com.atguigu.gmallpubliser.service.impl;

import com.atguigu.gmallpubliser.mapper.SugarMapper;
import com.atguigu.gmallpubliser.service.SugarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SugarServiceImpl implements SugarService {

    @Autowired
    private SugarMapper sugarMapper;

    @Override
    public BigDecimal getGmv(String date) {
        return sugarMapper.selectGmv(date);
    }

    @Override
    public Map<String, BigDecimal> getGmvByTm(String date, int limit) {

        //List[Map1[(tm_name->苹果),(order_amount->526411)],Map2[],Map3[],Map4[],Map5[]]
        List<Map> gmvByTm = sugarMapper.selectGmvByTm(date, limit);

        //Map[(苹果->526411),(华为->512222)...]
        HashMap<String, BigDecimal> resultMap = new HashMap<>();

        for (Map map : gmvByTm) {
            resultMap.put((String) map.get("trademark_name"), (BigDecimal) map.get("order_amount"));
        }

        return resultMap;
    }
}
